package edu.jd.software.web.backend.service.impl;

import edu.jd.software.web.backend.mongodb.document.MemberReadHistory;
import edu.jd.software.web.backend.mongodb.repository.MemberReadHistoryRepository;
import edu.jd.software.web.backend.service.MemberReadHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;


@Service
public class MemberReadHistoryServiceImpl implements MemberReadHistoryService {
    @Autowired
    private MemberReadHistoryRepository memberReadHistoryRepository;
    @Override
    public int create(MemberReadHistory memberReadHistory) {
        memberReadHistory.setId(null);
        memberReadHistory.setCreateTime(new Date());
        memberReadHistoryRepository.save(memberReadHistory);
        return 1;
    }

    @Override
    public int deleteById(List<String> ids) {
        List<MemberReadHistory> deleteList = new ArrayList<>();
        for(String id:ids){
            MemberReadHistory memberReadHistory = new MemberReadHistory();
            memberReadHistory.setId(id);
            deleteList.add(memberReadHistory);
        }
        memberReadHistoryRepository.deleteAll(deleteList);
        return ids.size();
    }

    @Override
    public List<MemberReadHistory> list(Long memberId) {
        return memberReadHistoryRepository.findByMemberIdOrderByCreateTimeDesc(memberId);
    }
    /**
     * 根据会员ID批量删除浏览记录-衍生方法
     */
    @Override
    public int deleteByMemId1(List<Long> memIds) {
        int count = 0;
        //todo
        return count;
    }

    /**
     * 根据会员ID批量删除浏览记录-利用衍生查询查出后的结果进行删除
     */
    @Override
    public int deleteByMemId2(List<Long> memIds) {
        int count=0;
        //todo
        return  count;
    }

    /**
     * 根据会员ID批量删除浏览记录-通过注解实现
     */
    @Override
    public int deleteByMemId3(List<Long> memIds) {
        int count=0;
        //todo
        return count;
    }

}
